package com.lxm.sevice.sen;

import com.alibaba.fastjson.JSONObject;
import com.lxm.action.ActionBase;
import com.lxm.entity.ReturnMessage;
import com.lxm.entity.UserEntity;
import com.lxm.entity.query.QuerySenData;
import com.lxm.util.HttpUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author ：Administrator
 * @date :创建时间 2021/12/29 12:42
 */
@Service
public class QQSendMsg implements senService {
    @Value("${urlPath.queryQQUrl}")
    private String queryQQUrl;

    @Override
    public ReturnMessage sneMsg(UserEntity user, QuerySenData querySenData) {
        String content = querySenData.getContent();
        if (content.length() >= 100) {
            content = content.substring(100) + "...";
        }
        if (user.getQqCode() == null ||user.getQqCode().isEmpty()) {
            return ActionBase.error("未绑定qq号");
        }
        JSONObject query = new JSONObject();
        query.put("message_type", "private");
        query.put("user_id", user.getQqCode());
        query.put("message", content);
        System.out.println(HttpUtils.post(queryQQUrl + "send_msg", query.toJSONString()));
        query.put("message", "[CQ:share,url=" + querySenData.getQueryUrl() + ",title=点击查看详情]");
        HttpUtils.post(queryQQUrl + "send_msg", query.toJSONString());
        return ActionBase.success();
    }


}
